<!-- 
  @name: 账号管理-调整收益比例
  @date: 2020.3.12
 -->
<template>
	<view class="content">
		<!-- 账号收益比例 -->
		<view class="set_num">
			<view class="num_int">
				<view class="_tip">收益比例</view>
				<view class="_btn les" @tap="count(1)"></view>
				<view class="_num"><input type="digit" v-model.number="earnRadio" /></view>
				<view class="_btn add" @tap="count(2)"></view>
				<view class="_tip2">%</view>
			</view>
		</view>
		
		<!-- 按钮 -->
		<button class="btn_submit" @tap="submit">确认</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				staffId: '',  //账户id
				earnRadio: 0,  //收益
				userIdentity: 0,  //账号身份
			}
		},
		onLoad(e) {
			this.staffId = e.staffId;
			this.earnRadio = e.earnRadio * 100;
			this.userIdentity = parseInt(e.userIdentity);
		},
		methods: {
			//增加减少领取数
			count(n) {
				if(n === 1) {
					if(this.earnRadio > 0) this.earnRadio -= 1;
				} else {
					if(this.earnRadio < 100) this.earnRadio += 1;
				}
			},
			//提交
			submit() {
				if(this.earnRadio === '' || this.earnRadio < 0 || this.earnRadio > 100) {
					this.$showToast('请输入正确的收益比例！');
					return;
				}
				let earnRadio = this.$operation(this.earnRadio, '/', 100);
				this.$http({
					url: this.$api.accountUrl + 'updateaccount',
					data: {
						staffId: this.staffId,
						userIdentity: this.userIdentity,
						type: 2,
						earnRadio: earnRadio
					}
				}).then(res => {
					this.$successToast('保存成功！');
					uni.$emit('setAcc_changeEarnRadio', {
						earnRadio: earnRadio
					});
					this.$sucBack();
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: $color-white;
	}
	
	/* 按钮 */
	.btn_submit {
		position: fixed;
		bottom: 0;
	}
</style>
